1435A - Finding Sasuke - CodeForces Solution


math *800

Please click on ads to support us..

C++ Code:

//
// Handle: stEV
//
// 11/25/2023
// 

#include <bits/stdc++.h>

using namespace std;

#define int long long

int n, a[107], b[107];

void solve() {
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    int l = 0, r = n - 1;
    if (n % 2) {
        b[l] = a[r] + a[r - 1], b[l] *= -1;
        b[r] = b[r - 1] = a[l];
        l++, r -= 2;
    }
    while (l < r) {
        b[l] = -a[r], b[r] = a[l];
        l++, r--;
    }
    for (int i = 0; i < n; ++i) {
        cout << b[i] << ' ';
    }
    cout << '\n';
}

int32_t main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t; cin >> t; while (t--) solve();
    return 0;
}


Comments

Submit
0 Comments
More Questions

1609C - Complex Market Analysis
1657E - Star MST
1143B - Nirvana
1285A - Mezo Playing Zoma
919B - Perfect Number
894A - QAQ
1551A - Polycarp and Coins
313A - Ilya and Bank Account
1469A - Regular Bracket Sequence
919C - Seat Arrangements
1634A - Reverse and Concatenate
1619C - Wrong Addition
1437A - Marketing Scheme
1473B - String LCM
1374A - Required Remainder
1265E - Beautiful Mirrors
1296A - Array with Odd Sum
1385A - Three Pairwise Maximums
911A - Nearest Minimums
102B - Sum of Digits
707A - Brain's Photos
1331B - Limericks
305B - Continued Fractions
1165B - Polycarp Training
1646C - Factorials and Powers of Two
596A - Wilbur and Swimming Pool
1462B - Last Year's Substring
1608B - Build the Permutation
1505A - Is it rated - 2
169A - Chores